//
//  WUFindViewController.m
//  Home
//
//  Created by 吴军虎吴军虎 on 16/5/4.
//  Copyright © 2016年 LanJue. All rights reserved.
//

#import "WUFindViewController.h"
#import "WUExpertFindViewCell.h"
#import "YHYAnimationDemo.h"
#import "WUDetailViewController.h"
#import "VippViewController.h"
#import "YHYFindSearchViewController.h"


@interface WUFindViewController ()<UITableViewDataSource,UITableViewDelegate,YHYAnimationDemoDelegate>

@property (nonatomic,retain)UITableView *myTableView;
@property (nonatomic,retain)WSCustomButton *singin, *SSbution;
@property (nonatomic,retain) UILabel *balabel;
@property (nonatomic,retain) NSArray *imageArray;
@property (nonatomic,retain) UIScrollView *BigScrollView;
@property (nonatomic,retain) YHYAnimationDemo *naView;

@end

@implementation WUFindViewController

- (void)viewWillAppear:(BOOL)animated {
    
    self.navigationController.navigationBarHidden = NO;
    self.navigationController.navigationBar.translucent = NO;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    [self creatView];
    self.navigationController.navigationBar.barTintColor = HEADVC;
    
    self.view.backgroundColor=LV;
    
    _imageArray=[NSArray arrayWithObjects:[UIImage imageNamed:@"ni"],[UIImage imageNamed:@"nn"],[UIImage imageNamed:@"wo"],[UIImage imageNamed:@"ww"],[UIImage imageNamed:@"to"],[UIImage imageNamed:@"tt"],[UIImage imageNamed:@"yo"],[UIImage imageNamed:@"yy"],[UIImage imageNamed:@"to"],[UIImage imageNamed:@"tt"], nil];
    
    
    //圆圈
    self.singin=[[WSCustomButton alloc]init];
    [self.singin setImage:[[UIImage imageNamed:@"QQ"]  imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
    self.singin.frame=CGRectMake(0, 0, 30 *AUTO_WIDTH, 30*AUTO_HEIGHT);
    [self.singin addTarget:self action:@selector(singinAction:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithCustomView:_singin];
    
    
    //100
    _balabel=[[UILabel alloc]init];
    _balabel.text=@"100";
    _balabel.textColor=[UIColor whiteColor];
    _balabel.textAlignment=NSTextAlignmentLeft;
    _balabel.font=[UIFont fontWithName:TFont size:TEXTCONTENTFONT * AUTO_WIDTH];
    [_singin addSubview:_balabel];
    [_balabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(_singin).offset(5 *AUTO_HEIGHT);
        make.left.equalTo(_singin).offset(0);
        make.size.mas_equalTo(CGSizeMake(28*AUTO_WIDTH, 20*AUTO_HEIGHT));
    }];
    
    
    //右边按钮
    self.SSbution = [WSCustomButton buttonWithType:UIButtonTypeCustom];
    self.SSbution.frame = CGRectMake(0, 0, 30, 30);
    [self.SSbution setImage:[[UIImage imageNamed:@"搜索"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
    // self.SSbution.backgroundColor = [UIColor whiteColor];
    [self.SSbution addTarget:self action:@selector(souSuo:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_SSbution];
    
    
}

-(void) button:(UIButton *)btn
{
    if (btn.tag == 1000) {
        self.BigScrollView.contentOffset = CGPointMake(0, 0);
    }
    
    if (btn.tag == 1001 ) {
        self.BigScrollView.contentOffset = CGPointMake(KScreenWidth, 0);
        
    }
    if (btn.tag == 1002) {
        self.BigScrollView.contentOffset = CGPointMake(KScreenWidth * 2, 0);
        
    }
    
    
}


- (void)creatView{
    
     _naView= [[YHYAnimationDemo alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40 * AUTO_WIDTH)];
    _naView.delegate=self;
    [self.view addSubview:_naView];
    
    
    self.BigScrollView = [[UIScrollView alloc]init];
    [self.view addSubview:self.BigScrollView];
    self.BigScrollView.delegate = self;
    self.BigScrollView.contentSize = CGSizeMake(self.view.frame.size.width*3, 0);
    self.BigScrollView.bounces = NO;
    self.BigScrollView.pagingEnabled = YES;
    self.BigScrollView.backgroundColor =LV;
    self.BigScrollView.pagingEnabled = YES;
    [self.BigScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.view.mas_top).offset(48 *AUTO_HEIGHT);
        make.size.mas_equalTo(CGSizeMake(self.view.frame.size.width, self.view.frame.size.height-100 *AUTO_HEIGHT));
        
    }];
    

    
    _myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-100*AUTO_HEIGHT)];
    _myTableView.backgroundColor = LV;
    _myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _myTableView.delegate = self;
    _myTableView.dataSource = self;
    [self.BigScrollView addSubview:_myTableView];

  
    
    
    [_myTableView registerClass:[WUExpertFindViewCell class] forCellReuseIdentifier:@"YHYFindViewCell"];
    
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *str = @"YHYFindViewCell";
    WUExpertFindViewCell *cell = [tableView dequeueReusableCellWithIdentifier:str forIndexPath:indexPath];
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    
    cell.myImageView.image=[_imageArray objectAtIndex:indexPath.row];
    
    return cell;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 750/3 * AUTO_HEIGHT;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    WUDetailViewController *detail = [WUDetailViewController new];
    detail.indexPath=indexPath;
    [self.navigationController pushViewController:detail animated:YES];
}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    
    if (scrollView == self.BigScrollView) {
        for (int i = 0; i < _naView.buttonArray.count; i++) {
            
            
            [UIView animateWithDuration:0.3 animations:^{
                
                UIButton * button = [_naView.buttonArray objectAtIndex:i];
                
                [button setTitleColor:HS forState:UIControlStateNormal];
                [button.titleLabel setFont:  [UIFont systemFontOfSize:AUTO_WIDTH*13.00]];
                
                
            }];
            
        }
        
        
        [UIView animateWithDuration:100 animations:^{
            
            
            UIButton *button=[_naView.buttonArray objectAtIndex:self.BigScrollView.contentOffset.x/self.view.frame.size.width];
            
            [button setTitleColor:GH forState:UIControlStateNormal];
            [button.titleLabel setFont:[UIFont systemFontOfSize:AUTO_WIDTH*15.00]];
            
            
        }];
        
    }
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    [_naView.LineView mas_updateConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.view).offset((KScreenWidth - 57.00* AUTO_WIDTH)/3/KScreenWidth * scrollView.contentOffset.x);
    }];
    
}



#pragma mark 搜索
- (void)souSuo:(UIButton *)sousuo{
    
    YHYFindSearchViewController *find = [YHYFindSearchViewController new];
    [self.navigationController pushViewController:find animated:YES];
    
}


-(void) singinAction:(UIButton *) btn
{
    VippViewController *vipp=[[VippViewController alloc]init];
    [self.navigationController pushViewController:vipp animated:YES];
}
@end

